class Animal {
    public String name;//成员属性
    public int age;
    public void eat() {
        System.out.println(name+"正在吃饭");
    }
}
class Dog extends Animal {
    public void wangwang() {
        System.out.println(name+"正在旺旺叫");
    }

    //private修饰的方法不能重写
    //static修饰的方法不能重写
    //子类的访问修饰限定权限要大于等于父类的权限
    //private<默认<protected<public
    //被final修饰的方法是不能被重写的
    //此时这个方法被称做密封方法

    @Override//注解：当前这个方法是被重写的
    public void eat() {
        System.out.println(name+ "正在吃狗粮");
    }
}
class Bird extends Animal {
    public String wing;//翅膀
    public void fly() {
        System.out.println(name+"正在飞");
    }

    @Override
    public void eat() {
        System.out.println(name+"正在吃鸟粮");
    }
}
public class DuoTai {

    public static void main(String[] args) {
        Animal animal = new Dog();
        //向下转型（不安全）
        Dog dog = (Dog)animal;//父类给到子类
        dog.name = "haha";
        dog.wangwang();

        System.out.println("=====");
        //可以理解为animal这个引用是不是引用了一个bird对象
        if (animal instanceof Bird) {
            Bird bird = (Bird) animal;
            bird.fly();
        }
    }

    public static void function(Animal animal) {
        animal.eat();
    }

    public static void main6(String[] args) {
        Animal animal = new Dog();//直接赋值
        animal.name = "十三月";
        function(animal);

        System.out.println("=======");
        Animal animal2 = new Bird();
        animal2.name = "yuanyuan";
        function(animal2);
    }

    public static int add(int a,int b) {
        return a+b;
    }
   //静态绑定
    public static int add(int a,int b,int c) {
        return a+b+c;
    }

    public static void main5(String[] args) {
        System.out.println(add(1, 2));
        System.out.println(add(1, 2,3));
    }

    public static void main4(String[] args) {
        Animal animal = new Dog();//直接赋值
        animal.name = "十三月";
        animal.eat();//动态绑定（了解）多态的基础
        //animal.wangawng();
        System.out.println("=======");
        Animal animal2 = new Bird();
        animal2.name = "yuanyuan";
        animal2.eat();
    }

    public static void func(Animal animal) {//方法的传参

    }

    public static Animal func2() {//方法的返回值
        return new Dog();
    }

    public static void main3(String[] args) {
        Dog dog = new Dog();
        func(dog);
    }

    public static void main2(String[] args) {
        //向上转型:发生多态的前提
        Animal animal = new Dog();//直接赋值
        animal.name = "十三月";
        animal.eat();
        //animal.wangawng();
        System.out.println("=======");
        Animal animal2 = new Bird();
        animal2.name = "yuanyuan";
        animal2.eat();
    }

    public static void main1(String[] args) {
        Dog dog = new Dog();
        dog.name = "十三月";
        dog.eat();
        dog.wangwang();

        Animal animal = dog;//向上转型
        Bird bird = new Bird();
        bird.name = "远远";
        Animal animal2 = bird;
    }
}
